import urllib.request
import xlwt
import requests
from lxml import etree
import time
import re
import mysql.connector
import os

# url = 'https://www.h128.com/tools/submit_ajax.ashx?action=user_down_count&jiage=0'
url = 'https://www.h128.com/tools/newdown.ashx'
cookie = '__yjs_duid=1_2b58545aba78c3fab4f512eb1ff4e5fb1625797129461; ASP.NET_SessionId=3qnfl03dcakknjudycpwd0tz; UM_distinctid=17a890f6890c2-04342169664c15-6373264-144000-17a890f68912b9; __gads=ID=b330cc091af63f7b-221e7eec42ca0062:T=1625797130:RT=1625797130:S=ALNI_MaoAd3oQTLcVJpSD9JIouWOpbJF5g; CNZZDATA1277605252=440962276-1625794280-https%253A%252F%252Fwww.baidu.com%252F%7C1625815970; dt_cookie_url_referrer=https%3a%2f%2fwww.h128.com%2flist%2f0%2f0%2f2%2f0%2f0%2fd.html; dt_cookie_user_name_remember=DTcms=%e5%8f%8b%e4%ba%baA1234567891011121314151617; dt_cookie_user_pwd_remember=DTcms=F9230DDA930A917EEF8DA463012F623E; Hm_lvt_51f818212e5bab6f247adcaa68213f43=1625797127,1625820061; Hm_lpvt_51f818212e5bab6f247adcaa68213f43=1625820107'

headers = {
    "authority": "www.h128.com",
    "method": "POST",
    "path": "/tools/newdown.ashx",
    "scheme": "https",
    "accept": "application/json, text/javascript, */*; q=0.01",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "zh-CN,zh;q=0.9",
    "content-length": "31",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
    "cookie": cookie,
    "origin": "https://www.h128.com",
    "referer": "https://www.h128.com/show-15792.html",
    "sec-ch-ua": '"Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',

    "sec-ch-ua-mobile": "?0",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
    "x-requested-with": "XMLHttpRequest"
}
data = {
    "site_id": 1,
    "id": 15792,
    "channel_id": 4
}
# opener = urllib.request.build_opener()
#
# urllib.request.install_opener(opener)
# urllib.request.urlretrieve(url,'./xx.png')
# urllib.request.urlretrieve(url,'./xx.png')
# request = urllib.request.Request(url=url, headers=headers)
#
# response = urllib.request.urlopen(request)
# print(response)
res = requests.post(url=url,data=data, headers=headers)
res.encoding = 'utf-8'

print(type(res.text))
print(res.text)
